package com.utils;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

/**
 * ClassName: CreateUserDir
 * Description:
 *      自定义一个用户目录生成工具类, 用于生成用户目录,并保存用户上传的文件
 * @author L_Z_R
 * @version 1.0
 * @create 2025/05/19 18:57
 */
public class CreateUserDir {
    public static String generateUserDirName(Path basePath, String username) throws IOException {
        int seq = 1;
        while (true) {
            String dirName = username + "_" + seq;
            Path candidate = basePath.resolve(dirName);
            if (!Files.exists(candidate)) {
                return dirName;
            }
            seq++;
        }
    }
}
